Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce assorted Iterator and Iterable Refaster rules #1487

Merged
merged 2 commits into from
Jan 7, 2025

Conversation

Stephan202
Copy link
Member

@Stephan202 Stephan202 commented Dec 29, 2024

Suggested commit message:

Introduce assorted `Iterator` and `Iterable` Refaster rules (#1487)

@Stephan202 Stephan202 added this to the 0.20.0 milestone Dec 29, 2024
Copy link
Member Author

@Stephan202 Stephan202 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change goes towards resolving #1088.

Comment on lines +73 to +89
// XXX: In practice this rule isn't very useful, as it only matches invocations of
// `assertThat(E)`. In most cases a more specific overload of `assertThat` is invoked, in which
// case this rule won't match. Look into a more robust approach.
static final class AssertThatIterableHasOneElementEqualTo<S, E extends S> {
@BeforeTemplate
ObjectAssert<S> before(Iterable<S> iterable, E element) {
return assertThat(Iterables.getOnlyElement(iterable)).isEqualTo(element);
}

@AfterTemplate
@UseImportPolicy(STATIC_IMPORT_ALWAYS)
IterableAssert<S> after(Iterable<S> iterable, E element) {
return assertThat(iterable).containsExactly(element);
}
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved from AssertJRules, mostly to keep track of this caveat.

Comment on lines -342 to -357
// XXX: This overload is here because `assertThat` has an overload for `Comparable` types.
// Unfortunately this still doesn't convince Refaster to match this rule in the context of
// Comparable types. Figure out why! Note that this also affects the `AssertThatOptional` rule.
static final class AssertThatIterableHasOneComparableElementEqualTo<
S extends Comparable<? super S>, T extends S> {
@BeforeTemplate
AbstractComparableAssert<?, S> before(Iterable<S> iterable, T element) {
return assertThat(Iterables.getOnlyElement(iterable)).isEqualTo(element);
}

@AfterTemplate
@UseImportPolicy(STATIC_IMPORT_ALWAYS)
IterableAssert<S> after(Iterable<S> iterable, T element) {
return assertThat(iterable).containsExactly(element);
}
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dropped this variant, since in practice it added little.

Copy link

Looks good. No mutations were possible for these changes.
Mutation testing report by Pitest. Review any surviving mutants by inspecting the line comments under Files changed.

Copy link
Contributor

@mohamedsamehsalah mohamedsamehsalah left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📁

@Stephan202
Copy link
Member Author

Validated that these changes do not impact the integration tests.

Copy link
Member

@rickie rickie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added one commit with a missing annotation :). Looks good!!

@Stephan202 Stephan202 force-pushed the sschroevers/assertj-iterator-and-iterable-rules branch from df11d54 to 7e5c40b Compare January 7, 2025 17:56
Copy link

github-actions bot commented Jan 7, 2025

Looks good. No mutations were possible for these changes.
Mutation testing report by Pitest. Review any surviving mutants by inspecting the line comments under Files changed.

Copy link

sonarqubecloud bot commented Jan 7, 2025

@Stephan202 Stephan202 merged commit dec22b8 into master Jan 7, 2025
16 checks passed
@Stephan202 Stephan202 deleted the sschroevers/assertj-iterator-and-iterable-rules branch January 7, 2025 18:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants